"""
响应处理工具函数
"""
from typing import Any, Optional


def api_response(
    code: int = 0,
    message: str = "操作成功",
    data: Optional[Any] = None
) -> dict:
    """
    生成标准API响应
    
    Args:
        code: 状态码，0表示成功，1表示失败
        message: 响应消息
        data: 响应数据
    
    Returns:
        标准响应字典
    """
    response = {
        "code": code,
        "message": message
    }
    
    if data is not None:
        response["data"] = data
    
    return response


def success_response(data: Any = None, message: str = "操作成功") -> dict:
    """
    成功响应
    
    Args:
        data: 响应数据
        message: 响应消息
    
    Returns:
        成功响应字典
    """
    return api_response(code=0, message=message, data=data)


def error_response(message: str = "操作失败", code: int = 1, data: Any = None) -> dict:
    """
    错误响应
    
    Args:
        message: 错误消息
        code: 错误码，默认为1
        data: 额外数据（可选）
    
    Returns:
        错误响应字典
    """
    return api_response(code=code, message=message, data=data)






